/**
 * 
 * @authors youzhao.zhou@pandauu.com
 * @date    2016-09-05 11:23:28
 * @version $Id$
 * 公共对象
 * 
 * 
 */


;(function(root,factory){

  if(typeof exports === 'object' && typeof module === 'object'){

    module.exports = factory(exports, require('./3_log'));

  } else if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['exports','./3_log'], factory);
  } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
    // CommonJS
    factory(exports, require('./3_log'));
  } else {
    // Browser globals
    root.Project = factory({},root.p_log);
  }

})((typeof window !== 'undefined' ? window : this) ,function(exports, log, undefined){
  'use strict';

  function Project(){
    this.df = 34;
  }

  Project.asd = {
    f : 'dfds'
  };

  Project.prototype.de = function(){
    console.log(213);
  };
  /*
    设置文本节点
  */
  Project.prototype.setHTML = function(selector, title){
    document.querySelector(selector).innerHTML = title;
  };
  /*
   模态框 点击关闭
  */
  /*Project.prototype.modalClose = function() {
    // body...
    var d = $('[data-s-dismiss]').data('s-dismiss');
      
    $('.' + d).on('tap', function(event) {
      event.preventDefault();
      
        if ($(this).modal) {
        $(this).modal('toggle');
        }else{
          $(this).removeClass('in');
          $(this).css({display : 'none'});
        }
    });

  }*/

  /*
  * 获取浏览器url
  */
  Project.prototype.getQueryStringObj = function(){

    var qs = (location.search.length > 0 ? location.search.substring(1) : ''),
    args = {},

    items = qs.length ? qs.split('&'):[],
    item = null,
    name = null,
    value = null,

    i = 0,
    len = items.length;

    for (i=0 ; i < len; i++) {
        item = items[i].split('=');
        name = decodeURIComponent(item[0]);
        value = decodeURIComponent(item[1]);

        if (name.length) {
            args[name] = value;
        }
    }

    return args;
    
  };
  /*
    文字信息URL处理
  */
  Project.prototype.setUrl = function (str){
    /*
      验证是否带有请求头正则
    */
    var reg = /(http:\/\/|https:\/\/)/g;
    /*
      提取URL正则
    */
    var reg1 = /((http:\/\/|https:\/\/)(((\w|=|\?|\/|&|-)+)(\.)((\.|\w|=|\?|\/|&|-)+)))/g;
    var reg2 = /((\w|=|\?|\/|&|-)+)(\.)((\.|\w|=|\?|\/|&|-)+)/g;
    if (reg2.test(str)) {
      if (!reg.test(str)) {
        str = str.replace(str.match(reg2)[0], '<a class="url-style" href="' + "http://" + str.match(reg2)[0] + '">' + str.match(reg2)[0] + '</a>');
      }else{
        str = str.replace(reg1, '<a class="url-style" href="$1">$1</a>');
      }
    }

    log._log(str);
    return str;
  }
  /*
    发布/订阅

  */
  Project.prototype.pubSub = function (){
    var fucObj = {};
    var c = false;

    return {
      set: function(newC){
        c = newC;
      },
      get: function(){
        return c;
      },
      addEvent: function(type, fuc){
        
        fucObj[type] = fucObj[type]||[];
        fucObj[type].push(fuc);
      },
      fireEvent: function(type, data){
        if (!fucObj[type]||fucObj[type].length<=0) {
          log._log( '未注册' + type + '事件' );
          return false;
        }

        for(var i=0; i<fucObj[type].length; i++){
          fucObj[type][i].apply(this, Array.prototype.slice.call(arguments,1));
        }
      }
    };
  };
  Project.prototype.callbackFuc = function (callback){
    
    if (callback instanceof Array) {
      var len = callback.length;
      
      for(var i=0; i<len ; i++){
        callback[i].apply(this, Array.prototype.slice.call(arguments,1));
      }
    }else{
      callback.apply(this, Array.prototype.slice.call(arguments,1));
    }

      
  };

  return Project;
});